import { createSlice } from '@reduxjs/toolkit'
import { setCookie, getCookie } from '@/utils'

export const Token = createSlice({
  name: 'token',
  initialState: {
    value: getCookie('token') || ''
  },
  reducers: {
    saveToken: (state, action) => {
      state.value = action.payload
      setCookie('token', action.payload) 
    }
  }
})

export const { saveToken } = Token.actions
export default Token.reducer